package com.xxxx.dao.impl;

import com.xxxx.dao.CourseDao;
import com.xxxx.domain.Course;
import com.xxxx.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

public class CourseDaoImpl implements CourseDao {
    JdbcTemplate jdbcTemplate=new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public void save(Course c) {
        String sql="insert into course values (?,?,?)";
        int update = jdbcTemplate.update(sql, c.getCno(), c.getCname(), c.getClassHour());
    }

    @Override
    public List<Course> findAll() {
        String sql="select * from course";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Course.class));
    }
}
